package com.yami.shop.service.impl;

import com.yami.shop.bean.cashregisterapp.AppCashRegister;
import com.yami.shop.dao.AppCashRegisterSystemUserMapper;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.shop.service.AppCashRegisterSystemUserService;
import com.yami.shop.bean.cashregisterapp.AppCashRegisterSystemUser;
import org.springframework.security.crypto.password.PasswordEncoder;
import java.util.List;


@Service
@AllArgsConstructor
public class AppCashRegisterSystemUserServiceImpl extends
        ServiceImpl<AppCashRegisterSystemUserMapper,AppCashRegisterSystemUser> implements AppCashRegisterSystemUserService{

    private final AppCashRegisterSystemUserMapper appCashRegisterSystemUserMapper;


    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public void deleteCashRegisterSystemUserByIds(List<Long> ids){
        appCashRegisterSystemUserMapper.deleteCashRegisterSystemUserByIds(ids);
    }

    @Override
    public AppCashRegisterSystemUser getByName(String name){
        return appCashRegisterSystemUserMapper.getByName(name);
    }

    @Override
    public boolean save(AppCashRegisterSystemUser appCashRegisterSystemUser){
        appCashRegisterSystemUser.setPassword(passwordEncoder.encode(appCashRegisterSystemUser.getPassword()));
        int result =  appCashRegisterSystemUserMapper.insert(appCashRegisterSystemUser);
        if(result>0){
            return true;
        }else{
            return false;
        }
    }

    //校验用户
    @Override
    public AppCashRegisterSystemUser  checkUserPassword(AppCashRegisterSystemUser appCashRegisterSystemUser){
        return appCashRegisterSystemUserMapper.checkUserPassword(appCashRegisterSystemUser);
    }

    //用户修改密码
    @Override
    public int updateUserPassword(AppCashRegisterSystemUser appCashRegisterSystemUser){
        return appCashRegisterSystemUserMapper.updateUserPassword(appCashRegisterSystemUser);
    }

    //根据电话号码查询用户信息
    @Override
    public AppCashRegisterSystemUser getUserByPhone(String phone){
        return appCashRegisterSystemUserMapper.getUserByPhone(phone);
    }

	@Override
    public AppCashRegisterSystemUser getAppCashRegisterSystemUserByUserId(Long userId) {
        return appCashRegisterSystemUserMapper.getAppCashRegisterSystemUserByUserId(userId);
    }

}
